const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const Permission = sequelize.define('Permission', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '权限名称'
  },
  code: {
    type: DataTypes.STRING,
    allowNull: false,
    unique: true,
    comment: '权限代码'
  },
  description: {
    type: DataTypes.TEXT,
    comment: '权限描述'
  },
  module: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '模块名称'
  },
  type: {
    type: DataTypes.ENUM('menu', 'operation', 'api'),
    defaultValue: 'operation',
    comment: '权限类型'
  },
  status: {
    type: DataTypes.ENUM('active', 'inactive'),
    defaultValue: 'active',
    comment: '权限状态'
  }
}, {
  indexes: [
    {
      unique: true,
      fields: ['code'],
      comment: '权限代码索引'
    }
  ],
  comment: '权限信息表'
});

module.exports = Permission; 